import { System } from "@/FrontProcessing/System/System";
import { debounce } from "stl-typescript";
import { devtool, IMouseEvent } from "cax-base";
import { GyActor } from "@/FrontProcessing/Actors/GyActor";

export const func_trim_by_nodes = debounce(
  (event: IMouseEvent, sys: System) => {
    const pos = event.position;
    const point = [pos.x, pos.y, 0.0];
    devtool.info(`🟢 当前选择点: ${point}`);
    sys.app.selector.vtPicker.pick(point, sys.app.renderer);
    if (sys.app.selector.vtPicker.getActors().length !== 0) {
      const modelPosition = sys.app.selector.vtPicker.getMapperPosition();
      const pickedCellId = sys.app.selector.vtPicker.getCellId();
      devtool.info(`🟢 当前选择index: ${pickedCellId}`);
      const back = sys.parent.selectorComp.getFaceIdByCellIndex(
        sys.app.actorList,
        pickedCellId,
        sys.state,
        sys.app.selector.getPickedVTActors() as GyActor[]
      );

      sys.app.actorList.value.forEach((actor: any) => {
        if (actor.partId === back.partId) {
          const selectedEdgeIndexDict = actor.outlines.findPointOnEdge(
            modelPosition,
            back.faceId
          );
        }
      });
      sys.app.window.render();
    }
  },
  50,
  false
);
